package controllers

import (
	"fmt"
	"hello/models"

	"github.com/astaxie/beego/orm"
)

type CourseController struct {
	BaseController
}

type CourseResult struct {
	*Head
	Body models.Course `json:"body"`
}

func (this *CourseController) GetCourse() {
	tid, _ := this.GetInt("tid")
	wxid := this.GetString("wxid")

	course := models.Course{TeacherId: tid, Wxid: wxid}
	o := orm.NewOrm()
	err := o.Read(&course, "TeacherId", "Wxid")
	if err == orm.ErrNoRows {
		fmt.Println("no found")
	}

	res := this.setRetHead(0, "ok")
	result := new(CourseResult)
	result.Head = res
	result.Body = course

	this.Data["json"] = result

	this.ServeJSON()
}
